import 'package:flutter/material.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/models/report/evaluationLevelChartData.dart';
import 'package:ichinesereader/utils/helper.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:get/get.dart';

class EvaluationLevelMultipleSeries extends StatelessWidget {
  EvaluationLevelMultipleSeries(
      {Key? key,
      required this.levelChartData,
      required this.chartTitle,
      required this.xLabel,
      this.levelStandard = 'ICR',
      required this.yLabel})
      : super(key: key);
  final List<EvaluationLevelChart> levelChartData;
  final String chartTitle;
  final String xLabel;
  final String yLabel;
final String? levelStandard;

  @override
  Widget build(BuildContext context) {
    Log.debug('build evaluation Level chart Widget');
    //TooltipBehavior _tooltipbehavior = TooltipBehavior(enable: true);
    TooltipBehavior _tooltipbehavior = TooltipBehavior(
        enable: true,
        duration: 1800,
        //format: 'Level: ${point.x} \n Score: point.y',
        builder: (dynamic data, dynamic point, dynamic series, int pointIndex,
            int seriesIndex) {
          return Padding(
            padding: const EdgeInsets.all(2.0),
            child: Container(
                color: Colors.grey[100],
                child: Text(
                    '${series.name}\nLevel: ${point.x.toString()} \nScore: ${point.y.toString()}')),
          );
        });
    return SfCartesianChart(
        title: ChartTitle(
          text: this.chartTitle,
          textStyle: TextStyle(color: Theme.of(context).primaryColorDark),
        ),
        legend: Legend(isVisible: true, position: LegendPosition.top),
        tooltipBehavior: _tooltipbehavior,
        primaryXAxis:  CategoryAxis(
          plotBands: Constants.plotbandACTFL
              .where((element) => element.start < 5)
              .toList(),
        ),
        primaryYAxis: NumericAxis(
          title: AxisTitle(text: this.xLabel),
          minimum: 0,
          maximum: 10,
          interval: 1,
        ),
        series: <CartesianSeries>[
          ColumnSeries<EvaluationLevelChart, String>(
            dataSource: levelChartData,
            name: 'Listening'.tr,
            xValueMapper: (EvaluationLevelChart data, _) =>
                data.level.replaceAll('ACTFLLevel.', ''),
            yValueMapper: (EvaluationLevelChart data, _) => data.listening,
            color: hexStringToHexInt('#ed5565'),
            dataLabelSettings: DataLabelSettings(isVisible: false),
          ),
          ColumnSeries<EvaluationLevelChart, String>(
            dataSource: levelChartData,
            name: 'Reading'.tr,
            xValueMapper: (EvaluationLevelChart data, _) =>
                data.level.replaceAll('ACTFLLevel.', ''),
            yValueMapper: (EvaluationLevelChart data, _) => data.reading,
            color: hexStringToHexInt('#23c6c8'),
            dataLabelSettings: DataLabelSettings(isVisible: false),
          ),
          ColumnSeries<EvaluationLevelChart, String>(
            dataSource: levelChartData,
            name: 'Speaking'.tr,
            xValueMapper: (EvaluationLevelChart data, _) =>
                data.level.replaceAll('ACTFLLevel.', ''),
            yValueMapper: (EvaluationLevelChart data, _) => data.speaking,
            color: hexStringToHexInt('#f8ac59'),
            dataLabelSettings: DataLabelSettings(isVisible: false),
          ),
          ColumnSeries<EvaluationLevelChart, String>(
            dataSource: levelChartData,
            name: 'Writing'.tr,
            xValueMapper: (EvaluationLevelChart data, _) =>
                data.level.replaceAll('ACTFLLevel.', ''),
            yValueMapper: (EvaluationLevelChart data, _) => data.writing,
            color: hexStringToHexInt('#1ab394'),
            dataLabelSettings: DataLabelSettings(isVisible: false),
          ),
          ColumnSeries<EvaluationLevelChart, String>(
            dataSource: levelChartData,
            name: 'AI Speaking        '.tr,
            xValueMapper: (EvaluationLevelChart data, _) =>
                data.level.replaceAll('ACTFLLevel.', ''),
            yValueMapper: (EvaluationLevelChart data, _) => data.aiSpeaking,
            color: hexStringToHexInt('#9d98f4'),
            dataLabelSettings: DataLabelSettings(isVisible: false),
          ),
        ]);
  }
}
